// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   register_ok.java

package manufacture.procedure;

import include.nseer_cookie.counter;
import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class register_ok extends HttpServlet
{

	public register_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 manufacture_db = new nseer_db_backup1(dbApplication);
		counter count = new counter(dbApplication);
		try
		{
			if (manufacture_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String manufacture_ID = request.getParameter("manufacture_ID");
				String product_ID = request.getParameter("product_ID");
				String product_name = request.getParameter("product_name");
				String product_describe = request.getParameter("product_describe");
				String amount = request.getParameter("amount");
				String pay_ID_group = request.getParameter("pay_ID_group");
				String designer = request.getParameter("designer");
				String register = request.getParameter("register");
				String register_time = request.getParameter("register_time");
				String bodyb = new String(request.getParameter("remark").getBytes("UTF-8"), "UTF-8");
				String remark = exchange.toHtml(bodyb);
				String design_ID = request.getParameter("design_ID");
				String choice_group = request.getParameter("choice_group");
				String procedure_ID[] = request.getParameterValues("procedure_ID");
				String procedure_name[] = request.getParameterValues("procedure_name");
				String procedure_describe[] = request.getParameterValues("procedure_describe");
				String labour_hour_amount[] = request.getParameterValues("labour_hour_amount");
				String amount_unit[] = request.getParameterValues("amount_unit");
				String cost_price[] = request.getParameterValues("cost_price");
				String subtotal[] = request.getParameterValues("subtotal");
				double module_cost_price_sum = 0.0D;
				double labour_cost_price_sum = 0.0D;
				for (int i = 0; i < procedure_name.length; i++)
				{
					int j = i + 1;
					double module_subtotal = 0.0D;
					labour_cost_price_sum += Double.parseDouble(subtotal[i]);
					String sql1 = (new StringBuilder("select * from manufacture_design_procedure_module_details where design_ID='")).append(design_ID).append("' and procedure_name='").append(procedure_name[i]).append("'").toString();
					String sql2;
					for (ResultSet rs1 = manufacture_db.executeQuery(sql1); rs1.next(); manufacture_db.executeUpdate(sql2))
					{
						double module_amount = rs1.getDouble("amount") * Double.parseDouble(amount);
						double subtotal1 = rs1.getDouble("cost_price") * module_amount;
						module_subtotal += subtotal1;
						module_cost_price_sum += subtotal1;
						sql2 = (new StringBuilder("insert into manufacture_procedure_module(manufacture_ID,procedure_name,details_number,product_ID,product_name,product_describe,type,amount,amount_unit,cost_price,subtotal) values('")).append(manufacture_ID).append("','").append(procedure_name[i]).append("','").append(rs1.getString("details_number")).append("','").append(rs1.getString("product_ID")).append("','").append(rs1.getString("product_name")).append("','").append(rs1.getString("product_describe")).append("','").append(rs1.getString("type")).append("','").append(module_amount).append("','").append(rs1.getString("amount_unit")).append("','").append(rs1.getString("cost_price")).append("','").append(subtotal1).append("')").toString();
					}

					String sql = (new StringBuilder("insert into manufacture_procedure(manufacture_ID,details_number,procedure_ID,procedure_name,procedure_describe,labour_hour_amount,amount_unit,cost_price,subtotal,module_subtotal) values('")).append(manufacture_ID).append("','").append(j).append("','").append(procedure_ID[i]).append("','").append(procedure_name[i]).append("','").append(procedure_describe[i]).append("','").append(labour_hour_amount[i]).append("','").append(amount_unit[i]).append("','").append(cost_price[i]).append("','").append(subtotal[i]).append("','").append(module_subtotal).append("')").toString();
					manufacture_db.executeUpdate(sql);
				}

				String sql3 = (new StringBuilder("insert into manufacture_manufacture(manufacture_ID,product_ID,product_name,product_describe,amount,pay_ID_group,apply_id_group,module_cost_price_sum,labour_cost_price_sum,register_time,designer,register,remark,check_tag,excel_tag) values('")).append(manufacture_ID).append("','").append(product_ID).append("','").append(product_name).append("','").append(product_describe).append("','").append(amount).append("','").append(pay_ID_group).append("','").append(choice_group).append("','").append(module_cost_price_sum).append("','").append(labour_cost_price_sum).append("','").append(register_time).append("','").append(designer).append("','").append(register).append("','").append(remark).append("','0','2')").toString();
				manufacture_db.executeUpdate(sql3);
				String sql4;
				for (StringTokenizer tokenTO = new StringTokenizer(choice_group, ","); tokenTO.hasMoreTokens(); manufacture_db.executeUpdate(sql4))
					sql4 = (new StringBuilder("update manufacture_apply set manufacture_tag='1' where id='")).append(tokenTO.nextToken()).append("'").toString();

				int num = count.read((String)dbSession.getAttribute("unit_db_name"), "manufacturecount");
				count.write((String)dbSession.getAttribute("unit_db_name"), "manufacturecount", num);
				manufacture_db.commit();
				manufacture_db.close();
				response.sendRedirect((new StringBuilder("manufacture/procedure/register_ok_a.jsp?manufacture_ID=")).append(manufacture_ID).toString());
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
